package net.mof.manual.meta

import com.squareup.javapoet.CodeBlock
import com.squareup.javapoet.TypeName
import net.mof.manual.MarkedClassInfo
import net.mof.manual.Utils.jsonObject
import javax.lang.model.element.Element

/**
 * 被标记类里的单个字段
 *
 * Created by LiYueHui on 2020/2/2.
 */
abstract class BaseFieldMetaInfo {
    // annotation value变量的名称
    var value: String? = null
    var element: Element? = null

    fun filedName(): String = element?.simpleName.toString()

    fun jsonToTypeGetField(builder: CodeBlock.Builder, markedClassInfo: MarkedClassInfo) {
        builder.addStatement("\$T \$L = \$L.opt\$L(\$S)", instanceTypeName(), value,
                jsonObject, optField(), value)
        jsonToTypeGet(builder, markedClassInfo)
    }

    abstract fun instanceTypeName(): TypeName

    abstract fun optField(): String


    abstract fun jsonToTypeGet(builder: CodeBlock.Builder,
                               markedClassInfo: MarkedClassInfo)

    abstract fun typeToJsonObjectPut(builder: CodeBlock.Builder?,
                                     param: String?)
}


